package com.yunban.route;

import com.yunban.dto.RegisterReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.system.employee.domain.form.EmployeeAddForm;
import net.lab1024.sa.admin.module.system.employee.service.EmployeeService;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: lijiajun
 * @date: 2025-03-26
 * @version: 1.0
 */
@OperateLog
@RestController
@Tag(name = "用户注册")
public class RegisterController {

    @Resource
    private EmployeeService employeeService;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public ResponseDTO<String> register(RegisterReq req) {
        EmployeeAddForm employeeAddForm = new EmployeeAddForm();
        BeanUtils.copyProperties(req, employeeAddForm);
        // 手机号就是登录名
        employeeAddForm.setLoginName(req.getPhone());
        // 10 -> 游客、客户
        employeeAddForm.setDepartmentId(10L);
        // role = 39  客户角色
        employeeAddForm.setRoleIdList(List.of(39L));
        return this.employeeService.addEmployee(employeeAddForm);
    }
}